package net.cityside.dp.rp;

import java.awt.BorderLayout;
import java.util.Properties;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import org.apache.velocity.app.Velocity;

public class MainFrame extends JFrame {

  private static final long serialVersionUID = 1L;

  public static void main(String[] args) {
    init();
    SwingUtilities.invokeLater(new Runnable() {

      @Override
      public void run() {
        MainFrame frame = new MainFrame();
        frame.setVisible(true);
      }
    });

  }

  private static void init() {
    Properties ps = new Properties();
    ps.put("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    ps.put("resource.loader", "classpath");
    Velocity.init(ps);
  }

  public MainFrame() {
    setNimbusLookAndFeel();

    createUI();

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);
  }

  private void createUI() {
    PrintConsole printConsole = new PrintConsole();
    add(printConsole, BorderLayout.CENTER);
  }

  /** 设值Nimbus观感，失败返回false。 */
  public static boolean setNimbusLookAndFeel() {
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          return true;
        }
      }
    } catch (Exception e) {
    }
    return false;
  }

}